package com.zsk.shop.controller.app;

import com.tencentcloudapi.mgobe.v20201014.models.Team;
import com.zsk.shop.common.annotion.NoPermission;
import com.zsk.shop.common.base.BaseResponse;
import com.zsk.shop.common.base.page.BasePageParams;
import com.zsk.shop.common.utils.HttpContext;
import com.zsk.shop.common.utils.ToolUtil;
import com.zsk.shop.model.params.EditUserParams;
import com.zsk.shop.model.params.IdentityCertificationUserParams;
import com.zsk.shop.model.params.ShopUserLoginParams;
import com.zsk.shop.model.params.ShopUserRegParams;
import com.zsk.shop.model.results.*;
import com.zsk.shop.service.ShopOrderPointsService;
import com.zsk.shop.service.ShopUserService;
import com.zsk.shop.service.WxDecodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Ys
 * @date 2022年02月09日 16:39
 */
@RestController
@Api(tags = "用户相关")
@Validated
@RequestMapping("/shop/user")
public class ShopUserController {

    @Resource
    private ShopUserService shopUserService;
    @Resource
    private ShopOrderPointsService shopOrderPointsService;
    @Resource
    private WxDecodeService wxDecodeService;

    @NoPermission
    @ApiOperation("登录")
    @PostMapping("/login.do")
    public BaseResponse<LoginInfoResult> login(@RequestBody ShopUserLoginParams params) {
        return shopUserService.login(params);
    }

    @NoPermission
    @ApiOperation("注册")
    @PostMapping("/reg.do")
    public BaseResponse<LoginInfoResult> reg(@RequestBody ShopUserRegParams params) {
        return shopUserService.reg(params, null);
    }

    @ApiOperation("修改用户信息(头像，昵称，性别)")
    @PostMapping("/editUser.do")
    public BaseResponse editUser(@RequestBody EditUserParams params) {
        return shopUserService.editUser(params);
    }

    @ApiOperation("修改密码")
    @GetMapping("/updatePwdNew.do")
    public BaseResponse updatePwdNew(String pwdNew) {
        return shopUserService.updatePwdNew(pwdNew);
    }

    @ApiOperation("第一次添加密码")
    @GetMapping("/insertPwd.do")
    public BaseResponse insertPwd(String pwdNew) {
        return shopUserService.insertPwd(pwdNew);
    }

    @ApiOperation("我的邀请列表")
    @PostMapping("/mineInviteUserList.do")
    public BaseResponse<MineInviteUserInfoResult> mineInviteUserList(@RequestBody BasePageParams params) {
        return shopUserService.mineInviteUserList(params);
    }

    @ApiOperation("我的邀请列表-至尊")
    @PostMapping("/mineInviteUserSupremeList.do")
    public BaseResponse<List<MineInviteUserListResult>> mineInviteUserSupremeList() {
        return shopUserService.mineInviteUserSupremeList();
    }

    @PostMapping("/certification.do")
    @ApiOperation("实名认证（新增）")
    public BaseResponse certification(@RequestBody @Validated IdentityCertificationUserParams params) {
        return shopUserService.certification(params);
    }

    @ApiOperation("个人中心用户信息")
    @PostMapping("/centerInfo.do")
    public BaseResponse<ShopUserCenterInfoResult> centerInfo() {
        return shopUserService.centerInfo(false);
    }

    @ApiOperation("填写邀请人")
    @GetMapping("/setParentUser.do")
    public BaseResponse setParentUser(String inviteCode) {
        if (ToolUtil.isEmpty(inviteCode)) {
            return BaseResponse.error("当前邀请码填写有误。");
        }
        return shopUserService.setParentUser(inviteCode);
    }

    @ApiOperation("查看推荐人")
    @PostMapping("/seeParentUser.do")
    public BaseResponse<SeeParentUserResult> seeParentUser() {
        return shopUserService.seeParentUser();
    }

    @ApiOperation("购物积分-用户积分明细列表")
    @GetMapping("/shopUserPointDetailList.do")
    public BaseResponse<ShopUserPointDetailResult> shopUserPointDetailList(String month, String page, String limit) {
        String userNo = HttpContext.getUserNo();
        return shopOrderPointsService.shopUserPointDetail(month, userNo, page, limit);
    }

    @NoPermission
    @ApiOperation("购物积分-用户积分明细详情")
    @GetMapping("/ShopOrderPointsDetail.do")
    public BaseResponse<ShopOrderPointsDetailResult> shopOrderPointsDetailDetail(String orderPointsNo, String page, String limit) {
        return shopOrderPointsService.shopOrderPointsDetailDetail(orderPointsNo, page, limit);
    }

    @ApiOperation("购物积分-已拆除列表")
    @PostMapping("/shopUserCanUsePointList.do")
    public BaseResponse<List<ShopOrderPointsListResult>> shopUserCanUsePointList(@RequestBody BasePageParams params) {
        return shopOrderPointsService.shopUserCanUsePointList(params);
    }

    @PostMapping("/removeAccount.do")
    @ApiOperation("注销账号")
    public BaseResponse removeAccount() {
        return shopUserService.removeAccount();
    }

    @NoPermission
    @ApiOperation(value = "微信移动端授权登录")
    @GetMapping(value = "/weChat/decode.do")
    @ApiImplicitParam(name = "code", value = "code")
    public BaseResponse<AppUserDecodeResult> wxDecode(String code) {
        return wxDecodeService.wxDecode(code);
    }


    @ApiOperation(value = "授权登录后，账号绑定手机，校验被绑定手机号")
    @GetMapping(value = "/bingPhone.do")
    @ApiImplicitParams({@ApiImplicitParam(name = "phone", value = "被绑定的手机号"),
            @ApiImplicitParam(name = "code", value = "前者短信验证码"),
            @ApiImplicitParam(name = "type", value = "授权登录类型 EnumDecodeType 1微信2钉钉3QQ4APPLE")})
    public BaseResponse<String> bingPhone(String phone, String code, Integer type) {
        return shopUserService.bingPhone(phone, code, type);
    }

    @NoPermission
    @ApiOperation(value = "团队业绩")
    @PostMapping(value = "/teamAmount.do")
    public BaseResponse<AppTeamAmountResult> teamAmount() {
        return shopUserService.teamAmount();
    }


    @NoPermission
    @ApiOperation(value = "用户的上下级手机号")
    @GetMapping(value = "/getUserList.do")
    public List<String> getUserList(String phone){
        return shopUserService.getUserList(phone);
    }

}
